
/*
 *
 *  * Copyright (c) 2013.
 *  * 游戏服务器核心代码编写人陈磊拥有使用权
 *  * 联系方式：E-mail:13638363871@163.com ;qq:502959937
 *  * 个人博客主页：http://my.oschina.net/chenleijava
 *
 */

package com.dc.gameserver.serverCore.controller.handleController.LoginController;

import com.dc.gameserver.proto.adminserverprotoVo.verificationRequest;
import com.dc.gameserver.proto.adminserverprotoVo.verificationResponse;
import com.dc.gameserver.serverCore.controller.AbstractController.AbstractController;
import com.dc.gameserver.serverCore.controller.AbstractController.IController;
import com.dc.gameserver.serverCore.model.dbsql.modelService.PlayerService;
import com.dc.gameserver.serverCore.model.dbsql.modelVo.TRole;
import com.dc.gameserver.serverCore.service.character.PlayerInstance;
import com.google.protobuf.MessageLite;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author : 石头哥哥
 *         Project : LandlordsServer
 *         Date: 13-6-4
 *         Time: 上午11:49
 *         Connect: 13638363871@163.com
 *         packageName: Server.ServerCore.Controller
 *         验证用户名是否重复
 */
@Service
public class verificationNameController extends AbstractController {

    @Resource
    private PlayerService playerService;

    @Override
    public void PostConstruct() {
        int ID= verificationRequest.msgID.ID_VALUE;
        GAME_CONTROLLERS[ID]=this;
        IController.MESSAGE_LITE[ID]= verificationRequest.getDefaultInstance();
    }

     /**
     * messageLite数据结构体分发
     * @param messageLite
     * @param player
     * @throws Exception
      *
     */
    @Override
    public void DispatchMessageLit(MessageLite messageLite, PlayerInstance player) throws Exception {
        verificationRequest verificationRequest= (verificationRequest) messageLite;
        String  roleName=  verificationRequest.getRoleName();
        verificationRequest=null;
        verificationResponse.Builder builder=verificationResponse.newBuilder();
        TRole tRole=playerService.checkRole(roleName);   //查询数据库是否存在此帐号
        if (tRole!=null){      //角色名称已注册，创建角色失败
            builder.setResult(0x2);
        }else {
            builder.setResult(0x1);
        }
        player.DirectSend(wrappedBufferShort(verificationResponse.msgID.ID_VALUE, builder.build()));
    }
}
